<?php

namespace app\saas\controller;

use app\admin\controller\CommonController;
use app\common\util\ErrorCode;
use app\saas\service\LoginService;
use think\App;

class BaseController extends CommonController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
    }

    /* 获取在缓存中或数据库中用户登录的数据 */
    public function getSessionIdVar($sessionId, $key = '')
    {
        $manageData = LoginService::checkSession($sessionId);
        if (isset($manageData["code"])) {
            $this->returnData = $manageData;
            return false;
        }
        if (is_bool($manageData) && !$manageData) {
            $this->returnData = ErrorCode::code("token_expire");
            return false;
        }
        request()->manageData = $manageData; // 把管理员信息存到request对象里，全局可以调用
        $this->isSuper = $manageData["type"] == '1' ? true : false; // 1 - 超级管理员 | 其它 - 普通管理员
        if (empty($key)) {
            return $manageData;
        }
        if (array_key_exists($key, $manageData)) {
            return $manageData[$key];
        } else {
            return '';
        }
    }
}
